# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

# Contributor: Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
# Contributor: David Stelter <david.stelter@gmail.com>
# Contributor: Francisco Lopes <chico.lopes@gmail.com>

pkgname=pfff
pkgver=0.29
pkgrel=10
pkgdesc='Tools and APIs for code analysis, visualization and transformation'
groups=('blackarch' 'blackarch-code-audit')
arch=('x86_64' 'aarch64')
url='https://github.com/facebook/pfff'
license=('LGPL')
depends=('zlib')
optdepends=('gtk2: required by codegraph and codemap')
makedepends=('ocaml' 'ocaml-findlib' 'ocaml-stdlib-shims' 'camlp4')
options=(!makeflags staticlibs !strip) # parallel build fails, need *.a files
source=("$pkgver.tar.gz::https://github.com/facebook/pfff/archive/v$pkgver.tar.gz"
        'lang_js-analyze-module_js.ml-Fix-invalid-documentati.patch'
        'lang_js-analyze-utils_js.mli.patch'
        '0001-Replace-use-of-uint32-by-standard-complient-way.patch'
        '0001-external-ocamlzip-zip.ml-remove-duplicate-exception.patch'
        '0001-lang_php-matcher-Makefile-remove-warn-error.patch'
        'unused-module.patch')
sha512sums=('62273530faa2bbf359686f1777f178c9496e8ec501bf5431d9b37e24267a5797d7fc088ffac226832d5588c5d75833c06070d51386a9d07e4ee87bac784f2595'
            '80a99ad238004973c4b8cef8808b969e1ba14e0f32af6a64e5f0461f93efa85e03661d95ab86c056f0ebdab7c66e236ebb4088cd3271c3bd2ce7a84714a42993'
            '4e4851a1379bd1100a198c4deb57efa3f44b7c4551ab3f202bd9b84215139cda1454f95294f9e2c1525c4850816816493de70efbce52f80a89753eda8190f840'
            '886d043fd21dc34b248c8dbe14e843eeed7fadd707c2ca89bb41f953879910d9f2d7332f7e775f8bbb025323a9404441f41870e6b1f9579281a7181afc020f05'
            '645fd094aebce646a1f8bec793d6c7f4934a942151afda25c59eb9d95086dd703680d65d97a19a87bd3b76c0354f6f308dc8b091e9905f4e129d9f1e3e3f2aaa'
            'a8d72911ef72ca2b5d6cad83f1fb5d55cb534213947c22b54d04b7c776e23957b6cc49c1813ee5e354a4f0b9c12841a5202451d138cf75dfb0837057fe8c956a'
            'd60a4c0364f14a116981e5b47fda85d8f00a8f3a5de6be249a9f259e661faee0a93d34ea2d0a56e0d5c5e13382b1e25b003ba62a4e128a747e67204fcfdf5f43')

prepare() {
	cd "$pkgname-$pkgver"

	patch -Np1 -i ../0001-Replace-use-of-uint32-by-standard-complient-way.patch
	patch -Np1 -i ../0001-external-ocamlzip-zip.ml-remove-duplicate-exception.patch
	patch -Np1 -i ../0001-lang_php-matcher-Makefile-remove-warn-error.patch
	patch -Np1 -i ../lang_js-analyze-utils_js.mli.patch
	patch -Np1 -i ../lang_js-analyze-module_js.ml-Fix-invalid-documentati.patch
	patch -Np1 -i ../unused-module.patch

  sed 's|/usr/local/|/usr/|g' -i external/ocamlzip/Makefile
}

build() {
	cd "$pkgname-$pkgver"

	./configure --prefix=/usr

  WARNING_FLAGS="-w +A-4-29-6-45-41-44-48" make clean depend all opt
}

package() {
	cd "$pkgname-$pkgver"

	install -dm 755 "$pkgdir/usr/lib/ocaml"

  make DESTDIR="$pkgdir" install
	make OCAMLFIND_LDCONF="$pkgdir/tmp/ld.conf" \
    OCAMLFIND_DESTDIR="$pkgdir/usr/lib/ocaml" install-findlib
}

